package com.yuan.task.service.impl;


import cn.common.exception.BusinessException;
import com.yuan.task.service.ResilienService;
//import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ResilienServiceImpl implements ResilienService {

    @Override
//    @CircuitBreaker(name = "myCircuitBreaker", fallbackMethod = "fallback")
    public String doSomething(Integer n) {
        //double random = Math.random();
        //log.info("Generated random value: {}", random);
        if (n == 1) {
            log.error("Simulated error occurred");
            throw new BusinessException("Simulated error");
        }else {
            return "Success";
        }
        //log.info("Operation succeeded");

    }

    public String fallback(Exception e) {
        log.info("Fallback method is called due to error: {}", e.getMessage());
        return "Fallback response due to error: " + e.getMessage();
    }
}
